package com.wd.mylibrary_square.view.activity

import android.content.Context
import android.util.AttributeSet
import android.view.ViewGroup

/**
 * 作者: 邢凌志
 * 时间: 2024/9/24
 * 描述:
 */
class SearchView(context: Context?, attrs: AttributeSet?) : ViewGroup(context, attrs) {
    override fun onLayout(p0: Boolean, p1: Int, p2: Int, p3: Int, p4: Int) {
        var width=20
        var height=10

        //流式布局
        for (i in 0 until  childCount) {
            val child=getChildAt(i)
            var measureWidth=child.measuredWidth
            var measureHeight=child.measuredHeight

            if(width+measureWidth>this.width){
                height+=measureHeight+10
                width=20
            }
            child.layout(width,height,width+measureWidth,height+measureHeight)
            width+=measureWidth
        }
    }

    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec)
        measureChildren(widthMeasureSpec,heightMeasureSpec)
    }
}